import java.util.Scanner;

public class GessNumber {
    public static void main(String[] args) {
        //1.打印提示信息
        System.out.println("欢迎来到猜数字!");
        Scanner scanner = new Scanner(System.in);

        while (true){
            int answer = (int) (Math.random()*100+1);

            //3.接受玩家输入的猜测数字

            int chances = 7;

            while (chances>0){
                System.out.println("请输入一个1-100之间的整数,输入小于0的数结束游戏");
                System.out.println("还有"+chances+"次机会");
                int guess;
                try {
                    guess = scanner.nextInt();
                } catch (Exception e) {
                    System.out.println("请输入数字");
                    scanner.next();
                    continue;
                }


                //4.比较一次并给出反馈
                if (guess<0){
                    break;
                }else if (guess < answer){
                    System.out.println("小了！");
                }else if (guess > answer){
                    System.out.println("大了！");
                }else{
                    System.out.println("猜对了！");
                    break;
                }
                chances--;
            }
            System.out.println("还玩不（y/n）");
            String again = scanner.next();
            if ("y".equalsIgnoreCase(again)){
                System.out.println("再来一次");
            }else if (again.equalsIgnoreCase("n")){
                break;
            }
        }
        //2.生成1-100之间的数字

        //5.规定猜测次数

    }
}
